<?php
session_start();
require "../util/DBUtil.php";
/**
 * 商品详情页
 */
$sql = "select book.* ,store.storeName from book,store where book.storeNo = store.storeNo and bookNo = ?";
$pram = array($_GET['bookNo']);
$db = new DBUtil();
$bookInfo = $db->query1($sql,$pram)[0]; //存放图书信息
//print_r($bookInfo);
?>
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/details.css" rel="stylesheet">
<h5>店铺：<?php echo $bookInfo['storeName']?></h5>

<div class="container">
    <!--图片-->
    <div class="row">
        <div class="col-md-4">
            <img src=<?php echo '../img/' . $bookInfo[picture] ?> alt=<?php echo $bookInfo[bookName] ?>
                 class="img-responsive center-block"  width="360" >
        </div>
        <div class="col-md-8">
            <div class="row"><h3><?php echo $bookInfo['bookName'];?></h3></div>
            <div class="row"><br>作者：<?php echo $bookInfo['author']?>&nbsp;&nbsp;&nbsp;&nbsp;
                出版社：<?php echo $bookInfo['press']?><br><br>字数：<?php echo $bookInfo['wordNumber']?>万&nbsp;&nbsp;&nbsp;&nbsp;
                出版时间：<?php echo $bookInfo['outDate']?>
            </div>
            <div class="row price">嘟嘟价<br><span style="color: #f42424;font-size: 28px">&yen;<?php echo $bookInfo['price'] ?></span></div>
            <div class="row buy"><input type="number" max="5" min="1" value="1" id="num">
                <a href="" onclick=<?php echo isset($_SESSION['login_user'])? 'cart(1)':'cart(2)' ?> class="cart" id="a">
                    <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span>
                    <span>加入购物车</span>
                </a>
            </div>
        </div>
    </div>
    <!--解析json文件-->
    <?php
        $filename = "../details/".$bookInfo['description'];
//        echo $filename;
        $json_str = file_get_contents($filename);
        $date = json_decode($json_str,true);
    ?>
    <!--产品特色-->
    <div class="row">
        <div class="col-md-8">
            <h4 class="h4"><span>产品特色</span></h4>
            <img src=<?php echo '../img/details/'.$date['feature'] ?> alt="">
        </div>
    </div>
    <!--内容简介-->
    <div class="row">
        <div class="col-md-8">
            <h4 class="h4"><span>内容简介</span></h4>
            <div><?php echo $date['content'];?></div>
        </div>
    </div>
    <!--作者简介-->
    <div class="row">
        <div class="col-md-8">
            <h4 class="h4"><span>作者简介</span></h4>
            <div><?php echo $date['author'];?></div>
        </div>
    </div>
</div>

<!--携带参数-->
<script>
    function cart(flag) {

        var a = document.getElementById("a");
        switch(flag){
            case 1:
                a.href = "../action/join_cart.php?bookNo=<?php echo $bookInfo['bookNo']?>&onePrice=<?php echo $bookInfo['price']?>&"+"bookNum="+document.getElementById("num").value;
                break;
            case 2:
                a.href = "cart.php?bookNo=<?php echo $bookInfo['bookNo']?>&onePrice=<?php echo $bookInfo['price']?>&"+"bookNum="+document.getElementById("num").value;
                break;
        }

    }
</script>
